﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kimd.Communication
{
    public interface ISerialPort
    {
        /// <summary>
        /// 连接事件
        /// </summary>
        event EventHandler Connected;
        /// <summary>
        /// 断开事件
        /// </summary>
        event EventHandler Disconnected;
        /// <summary>
        /// 接收信息事件
        /// </summary>
        event EventHandler<DatagramReceivedEventArgs<byte[]>> DatagramReceived;
        /// <summary>
        /// 打开状态
        /// </summary>
        bool IsOpen { get; }
        /// <summary>
        /// 打开串口
        /// </summary>
        /// <returns></returns>
        bool Open();
        /// <summary>
        /// 关闭串口
        /// </summary>
        /// <returns></returns>
        bool Close();
        /// <summary>
        /// 发送信息,返回发送状态,接收结果
        /// </summary>
        /// <param name="send"></param>
        /// <param name="receive"></param>
        /// <param name="waitTime"></param>
        /// <returns></returns>
        bool Send(byte[] send,out string receive,int timeout=500);
        /// <summary>
        /// 发送信息,返回发送状态,接收结果
        /// </summary>
        /// <param name="send"></param>
        /// <param name="receive"></param>
        /// <param name="waitTime"></param>
        /// <returns></returns>
        bool Send(byte[] send,out byte[] receive,int timeout = 500);
        /// <summary>
        /// 发送信息,返回发送状态
        /// </summary>
        /// <param name="send"></param>
        /// <param name="waitTime"></param>
        /// <returns></returns>
        bool Send(byte[] send);
        /// <summary>
        /// 发送信息,返回发送状态,接收结果
        /// </summary>
        /// <param name="send"></param>
        /// <param name="waitTime"></param>
        /// <returns></returns>
        bool Send(String send, out string receive,int timeout = 500);
        /// <summary>
        /// 发送信息,返回发送状态,接收结果
        /// </summary>
        /// <param name="send"></param>
        /// <param name="receive"></param>
        /// <param name="waitTime"></param>
        /// <returns></returns>
        bool Send(String send, out byte[] receive, int timeout = 500);
        /// <summary>
        /// 发送信息,返回发送状态
        /// </summary>
        /// <param name="send"></param>
        /// <param name="waitTime"></param>
        /// <returns></returns>
        bool Send(String send);
    }
}
